<%@ page language="Java" import="java.util.*,descriptor.*,cv.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	CompaniesListDescriptor compList = (CompaniesListDescriptor)request.getAttribute("compList");
	CompaniesListDescriptor compPref = (CompaniesListDescriptor)request.getAttribute("compPref");
	String error1 = (String)request.getAttribute("error1");
	String error2 = (String)request.getAttribute("error2");
	
	String notif = "";
	if(error2 != null)
	{
		notif ="<p style=\"color:red; font-size: 10px;\">" + error2 + "</p>";
	}
%>

<html>
	<jsp:include page="StudentHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Student" />
	</jsp:include>
	<body OnLoad="showmenu(document.getElementById('smenu4'));">
		<jsp:include page="StudentPageHeader.jsp"></jsp:include>
		<div id="container">
			<jsp:include page="StudentMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Student - Matching Companies</h3>
				<div class="entry">
					<%= notif %>
					<%
							int sizeList = compList.getCompanyDescriptors().size(); 
							if(sizeList>0)
							{
					%>
					<table rules="all">
						<thead>
							<tr><th>Company Name</th><th>Sector</th><th>City</th><th>Country</th><th>Actions</th></tr>
						</thead>
					<%
								
								for(int i=0; i<sizeList; i++)
								{
									boolean sel = false;
									String name = compList.getCompanyDescriptors().get(i).getName();
									String sector = compList.getCompanyDescriptors().get(i).getSector();
									String city = compList.getCompanyDescriptors().get(i).getCity();
									String country = compList.getCompanyDescriptors().get(i).getCountry();
									int id = compList.getCompanyDescriptors().get(i).getId();
									String style = "";
									if(compPref != null)
									{
										int size = compPref.sizeCompaniesList();
										for(int j=0 ; j<size ; j++)
										{
											if(id == compPref.getCompanyDescriptors().get(j).getId())
											{
												sel = true;
											}
										}
									}
									if(sel)
									{
										style = "style=\"background-color: #66ee00;\"";
									}
					%>
						<tr <%= style %>>
							<td><h4><%= name %></h4></td>
							<td><%= sector %></td>
							<td><%= city %></td>
							<td><%= country %></td>
							<td>
								<form name="view<%= i %>" method="post">
									<input type="hidden" name="action" value="viewComp1">
									<input type="hidden" name="companyID" value="<%= id %>">     
								</form> 
								<a href="javascript:document.view<%= i %>.submit();" title="View Company: <%=  name %> Details">Details</a>
					<%
									if(!sel)
									{
					%>			
								<form name="select<%= i %>" method="post">
									<input type="hidden" name="action" value="selectComp">
									<input type="hidden" name="companyID" value="<%= id %>">   
								</form> 
								<a href="javascript:document.select<%= i %>.submit();" title="Select <%=  name %> as a favourite company" >Select</a>
					<%
									}
					%>
							</td>
						</tr>
				<%				}
				%>
					</table>
				<%
							}
							else
							{ 
								if(error1 != null)
				%>
									<p><%= error1 %></p>
								<form name="selectComp" method="post">
									<input type="hidden" name="action" value="setCompanies">     
								</form> 
								<a href="javascript:document.selectComp.submit();" title="Set up your preference">Set up your preferences</a>
								
				<%	 	
							} 
				%>
				</div>
	    	</div>
			<jsp:include page="StudentPageFooter.jsp"></jsp:include>
		</div>
	</body>
</html>